<?php

require_once 'pico.php';
require_once 'Table1.php';
require_once 'Table2.php';

$conn = new Connection(new PDO('mysql:host=localhost;dbname=orm;port=8889', 'root', 'root'));

PicoORM::instance()->addConnection('orm', $conn);
PicoORM::instance()->bindModelWithConnection('Table1','orm');
PicoORM::instance()->bindModelWithConnection('Table2','orm');

Query::on('Table1')->delete();
Query::on('Table2')->delete();

$table1a = new Table1();
$table1b = new Table1();
$table1c = new Table1();

$table2a = new Table2();
$table2a->pole1 = '1';
$table2a->pole_2 = 1;
$table2a->save();

$table2b = new Table2();
$table2b->pole1 = '2';
$table2b->pole_2 = 2;
$table2b->save();

$table1a->field1 = '1a';
$table1a->field2 = '1900-01-01';
$table1a->table = $table2a;
$table1a->save();

$table1b->field1 = '1b';
$table1b->field2 = '1900-01-02';
$table1b->table = $table2a;
$table1b->save();

$table1c->field1 = '1c';
$table1c->field2 = '1900-01-03';
$table1c->table = $table2b;
$table1c->save();

var_dump($table1a);
echo "<br /><br />";

var_dump($table1a->table);
echo "<br /><br />";

var_dump($table2a);
echo "<br /><br />";

var_dump($table2a->tables);
echo "<br /><br />";

var_dump($table2b->tables);
echo "<br /><br />";

$table = $table2a->tables[0];
$table->field1 = 'aaaa';
$table->save();
$table1a->reload();


var_dump($table2a->tables);
echo "<br /><br />";

var_dump($table1a);
echo "<br /><br />";

$table2a->delete();

?>